<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>树形表格组件</title>
    <link rel="icon" th:href="@{/images/favicon.ico}">
    <link rel="stylesheet" th:href="@{/layuimini/lib/layui-v2.6.3/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/layuimini/css/public.css}" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <div class="ok-body">
            <blockquote class="layui-elem-quote" style="padding: 5px;">
                1.layui第三方扩展组件：<font color="red" size="2">树形表格(treeTable)</font>；
                <a href="https://gitee.com/whvse/treetable-lay" target="_blank" class="layui-btn layui-btn-sm layui-btn-danger">treeTable</a>
                <br>
                2.本项目主要在菜单管理中使用，展示树形菜单；
            </blockquote>
            <div class="layui-row">
                <div class="layui-col-xs12 layui-col-sm12 layui-col-md6 layui-col-lg6">
                    <pre>
     // Step1. 引入依赖
    let treetable = layui.treetable;
    <br>

    // Step2. 使用
   treetable.render({
        treeColIndex: 1,
        treeSpid: -1,
        treeIdName: 'authorityId',
        treePidName: 'parentId',
        elem: '#menu-table',
        url: ctxPath+'layuimini/api/menus.json',
        page: false,
        cols: [
            [
                {type: 'numbers'},
                {field: 'authorityName', minWidth: 200, title: '权限名称'},
                {field: 'authority', title: '权限标识'},
                {field: 'menuUrl', title: '菜单url'},
                {field: 'orderNumber', width: 80, align: 'center', title: '排序号'},
                {field: 'isMenu', width: 80, align: 'center', templet: function (d) {
                        if (d.isMenu == 1) {
                            return '<span class="layui-badge layui-bg-gray">按钮</span>';
                        }
                        if (d.parentId == -1) {
                            return '<span class="layui-badge layui-bg-blue">目录</span>';
                        } else {
                            return '<span class="layui-badge-rim">菜单</span>';
                        }
                    }, title: '类型'
                },
                {templet: '#auth-state', width: 120, align: 'center', title: '操作'}
            ]
        ],
        done: function () {
            layer.closeAll('loading');
        }
    });
                    </pre>
                </div>
                <div class="layui-col-xs12 layui-col-sm12 layui-col-md6 layui-col-lg6">
                    <div style="padding-top: 10px;">
                        <div class="layui-btn-group">
                            <button class="layui-btn" id="btn-expand">全部展开</button>
                            <button class="layui-btn layui-btn-normal" id="btn-fold">全部折叠</button>
                        </div>
                        <table id="menu-table" class="layui-table" lay-filter="menu-table"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- 操作列 -->
<script type="text/html" id="auth-state">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<!--  引入layui框架js文件-->
<script th:src="@{/layuimini/lib/layui-v2.6.3/layui.js}" charset="utf-8"></script>
<script th:src="@{/layuimini/js/lay-config.js?v=1.0.4}" charset="UTF-8"></script>
<script type="text/javascript" th:inline="javascript">
    layui.use(["code","table","treetable"], function () {
        let code = layui.code;
        let table = layui.table;
        let treetable = layui.treetable;
        let $ = layui.jquery;

        let ctxPath = /*[[@{/}]]*/'';

        code({
            elem: "pre",
            title: "代码示例",
            encoded: true,
            skin:'notepad', //设置显示风格
            about: false
        });

        //多选
        treetable.render({
            treeColIndex: 1,
            treeSpid: -1,
            treeIdName: 'authorityId',
            treePidName: 'parentId',
            elem: '#menu-table',
            url: ctxPath+'layuimini/api/menus.json',
            page: false,
            cols: [
                [
                    {type: 'numbers'},
                    {field: 'authorityName', minWidth: 200, title: '权限名称'},
                    {field: 'authority', title: '权限标识'},
                    {field: 'menuUrl', title: '菜单url'},
                    {field: 'orderNumber', width: 80, align: 'center', title: '排序号'},
                    {
                        field: 'isMenu', width: 80, align: 'center', templet: function (d) {
                            if (d.isMenu == 1) {
                                return '<span class="layui-badge layui-bg-gray">按钮</span>';
                            }
                            if (d.parentId == -1) {
                                return '<span class="layui-badge layui-bg-blue">目录</span>';
                            } else {
                                return '<span class="layui-badge-rim">菜单</span>';
                            }
                        }, title: '类型'
                    },
                    {templet: '#auth-state', width: 120, align: 'center', title: '操作'}
                ]
            ],
            done: function () {
                layer.closeAll('loading');
            }
        });

        $('#btn-expand').click(function () {
            treetable.expandAll('#menu-table');
        });

        $('#btn-fold').click(function () {
            treetable.foldAll('#menu-table');
        });

        //监听工具条
        table.on('tool(menu-table)', function (obj) {
            let data = obj.data;
            let layEvent = obj.event;

            if (layEvent === 'del') {
                layer.msg('删除' + data.id);
            } else if (layEvent === 'edit') {
                layer.msg('修改' + data.id);
            }
        });
    });
</script>
</body>
</html>
